<?php
@session_start();
require_once '../../config/config.inc';
$conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
if(!$conn){
	echo mysql_error();
}

$db=mysql_select_db(DB_DATABASE);
if(!$db){
	mysql_error();
}
if(isset($_SESSION['USER_ID'])){
$id=$_SESSION['USER_ID'];	
}
if (isset($_POST['submit'])){
$txt;$ext;
	mysql_query("SET NAMES UTF8");
	mysql_query("SET CHARACHAR_SET UTF8");
	$path="../../assets/img/users/";
	$validformat=array("jpg","png","gif","bmp","JPG","PNG","GIF","BMP");
	$name=$_FILES['photo']['name'];
	$size=$_FILES['photo']['size'];
	if(strlen($name)){
		$r=1;
		list($txt,$ext)=explode(".",$name);
		if (is_array($validformat)){
			if($size<(1024*1024)*6){
				$r=3;
				$atual_name=substr(str_replace(" ","_", $txt), 5).".".$ext;
				$temp=$_FILES['photo']['tmp_name'];
				$insert=mysql_query("UPDATE`user` set photo='$atual_name' where id='$id'");
				if($insert){
					$movefile=move_uploaded_file($temp , $path.$atual_name);
					if(!$movefile){
						echo mysql_error();
						echo "FAILED";
						exit();
					}
					header("location:../profile.php?stats=suesses");
				}else{

					echo mysql_error()."not inserted dear please try agine";
				}

			}else{
				echo mysql_error()."name is not true";
			}
		}}
}else {
	echo mysql_error();
}	
	
?>